package com.mutual.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.mutual.constant.AdminSystemConstant;


@Component("baseInterceptor")
public class BaseInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		// 获取网站基准路基
		HttpSession session = request.getSession();
		String basePath = (String)session.getAttribute(AdminSystemConstant.BASE_PATH);
		if(StringUtils.isBlank(basePath)){
			// 设置网站基准路基
			basePath = WebUtils.getBasePath(request);
			session.setAttribute(AdminSystemConstant.BASE_PATH, basePath);
		}
		
		return super.preHandle(request, response, handler);
	}
}
